package mockdata;


import org.apache.commons.configuration.ConfigurationFactory;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;
import java.util.ArrayList;
public class UserProfileDatagen {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        conf.set("hbase.zookeeper.quorum","master3:2181,master4:2181,master5:2181");
        Connection conn = ConnectionFactory.createConnection(conf);
        Table htable = conn.getTable(TableName.valueOf("yiniu2"));

        //生成用户画像数据99人的数据
        for (int i = 0; i < 100; i++) {
            //把每个用户的还想数据模拟
            //设备id===rowkey
            String serviceId = StringUtils.leftPad(i + "", 2, "0");
            //一个设备会有多个列和对应的值
            //先创建一个put对象，里面传一个rowkey
            Put put = new Put(Bytes.toBytes(serviceId));

            ArrayList<Put> puts = new ArrayList<>();

                for (int k = 0; k < 100; k++) {
                    String key = k + "k";
                    String value = "v" + RandomUtils.nextInt(1, 100);
                    put.addColumn(Bytes.toBytes("f"), Bytes.toBytes(key), Bytes.toBytes(value));
                }
                puts.add(put);

            //提交一批数据
            htable.put(puts);
            puts.clear();
        }
        conn.close();
    }


}
